<?php
/**
 * Created by PhpStorm.
 * @author WYZ <wyz@jungo.com.cn>
 * @copyright 深圳市俊网网络有限公司
 */

namespace Selibra\MQ;


use Swoole\Coroutine;

class ProducerFactory
{

    /**
     * @var Producer[]
     */
    static array $producer = [];


    /**
     * @return Producer
     */
    public static function getInstantiation()
    {
        if( !isset(self::$producer[Coroutine::getCid()]) ){
            self::$producer[Coroutine::getCid()] = new Producer();
            // 协程结束，释放连接
            defer(function () { // 释放
                unset(self::$producer[Coroutine::getCid()]);
            });
        }
        return self::$producer[Coroutine::getCid()];
    }

}